package at.fhhagenberg.hydrac.backend.codegenerators;

import java.util.logging.Logger;

import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTActParamList;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAddrOfStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAlgDecl;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAlgDef;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAlgHead;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAlgParamList;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAndExpr;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTArraySpec;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTArrayType;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAssignStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTAttrSpec;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTBlock;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTBreakStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTCallStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTChar;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTClassType;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTCompoundSpec;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTCompoundType;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTConstDecl;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTDeleteStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTElseBlock;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTExpr;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTExprList;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTFact;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTFalseFact;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTForStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTHaltStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTIdent;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTIdentList;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTIfStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTInheritedFact;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTInputStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTInteger;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTMethodDecl;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTMethodDef;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTNestedExpr;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTNewStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTNodeExt;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTNotFact;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTNullFact;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTOrExpr;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTOutputStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTParamKind;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTPointer;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTProgram;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTQualifier;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTReal;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTRelExpr;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTRepeatStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTReturnStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTReturnType;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTSelector;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTSimpleExpr;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTSingleOutput;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTStart;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTString;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTTerm;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTTextStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTThisFact;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTTrueFact;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTType;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTTypeDecl;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTTypeSpec;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTVarDecl;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTVarSpec;
import at.fhhagenberg.hydrac.backend.javacc.nodes.ASTWhileStat;
import at.fhhagenberg.hydrac.backend.javacc.nodes.Node;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;

/**
 * Tree Code Generator
 * 
 * @author Thomas Fischl
 */
public class AstCodeGenerator extends AbstractCodeGenerator {

  public AstCodeGenerator(String fileName, ASTStart astTree, int nrOfSpaces, Logger logger) {
    super(fileName, astTree, nrOfSpaces, "/*", "*/", logger);
  }

  @Override
  protected void handleNode(Node node) {
    enterScope();

    ASTNodeExt n = (ASTNodeExt) node;

    String str = "";

    if (n.getIsAbstract()) {
      str = str + " abstract=\"true\"";
    }

    if (n.getIsBasedOn()) {
      str = str + " basedon=\"true\" ";
    }

    if (n.getIsPublic()) {
      str = str + " public=\"true\" ";
    }

    if (n.getIsStatic()) {
      str = str + " static=\"true\" ";
    }
    if (!Strings.isNullOrEmpty(n.getSign())) {
      str = str + " sign=\"" + n.getSign() + "\"";
    }
    if (!Strings.isNullOrEmpty(n.getValue())) {
      str = str + " value=\"" + n.getValue().replace("\"", "&quot;") + "\"";
    }
    if (n.getValues() != null && !n.getValues().isEmpty()) {
      str = str + " values=\"" + Joiner.on(" ,").join(n.getValues()) + "\"";
    }

    addNewLineAndString("<" + n.getClass().getSimpleName());
    if (!str.trim().isEmpty()) {
      addString(str);
    }
    addString(">");

    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      handleNode(node.jjtGetChild(i));
    }
    addNewLineAndString("</" + n.getClass().getSimpleName() + ">");

    leaveScope();
  }

  @Override
  protected void scopeAddSpaces() {
    for (int i = 0; i < scope * nrOfSpaces; i++) {
      sb.append(" ");
    }
  }

  @Override
  protected void handleASTActParamList(ASTActParamList node) {
  }

  @Override
  protected void handleASTAddrOfStat(ASTAddrOfStat node) {
  }

  @Override
  protected void handleASTAlgDecl(ASTAlgDecl node) {
  }

  @Override
  protected void handleASTAlgDef(ASTAlgDef node) {
  }

  @Override
  protected void handleASTAlgHead(ASTAlgHead node) {
  }

  @Override
  protected void handleASTAlgParamList(ASTAlgParamList node) {
  }

  @Override
  protected void handleASTAndExpr(ASTAndExpr node) {
  }

  @Override
  protected void handleASTArraySpec(ASTArraySpec node) {
  }

  @Override
  protected void handleASTArrayType(ASTArrayType node) {
  }

  @Override
  protected void handleASTAssignStat(ASTAssignStat node) {
  }

  @Override
  protected void handleASTAttrSpec(ASTAttrSpec node) {
  }

  @Override
  protected void handleASTBlock(ASTBlock node) {
  }

  @Override
  protected void handleASTBreakStat(ASTBreakStat node) {
  }

  @Override
  protected void handleASTCallStat(ASTCallStat node) {
  }

  @Override
  protected void handleASTChar(ASTChar node) {
  }

  @Override
  protected void handleASTClassType(ASTClassType node) {
  }

  @Override
  protected void handleASTCompoundSpec(ASTCompoundSpec node) {
  }

  @Override
  protected void handleASTCompoundType(ASTCompoundType node) {
  }

  @Override
  protected void handleASTConstDecl(ASTConstDecl node) {
  }

  @Override
  protected void handleASTDeleteStat(ASTDeleteStat node) {
  }

  @Override
  protected void handleASTElseBlock(ASTElseBlock node) {
  }

  @Override
  protected void handleASTExpr(ASTExpr node) {
  }

  @Override
  protected void handleASTExprList(ASTExprList node) {
  }

  @Override
  protected void handleASTFact(ASTFact node) {
  }

  @Override
  protected void handleASTFalseFact(ASTFalseFact node) {
  }

  @Override
  protected void handleASTForStat(ASTForStat node) {
  }

  @Override
  protected void handleASTHaltStat(ASTHaltStat node) {
  }

  @Override
  protected void handleASTIdent(ASTIdent node) {
  }

  @Override
  protected void handleASTIdentList(ASTIdentList node) {
  }

  @Override
  protected void handleASTIfStat(ASTIfStat node) {
  }

  @Override
  protected void handleASTInheritedFact(ASTInheritedFact node) {
  }

  @Override
  protected void handleASTInputStat(ASTInputStat node) {
  }

  @Override
  protected void handleASTInteger(ASTInteger node) {
  }

  @Override
  protected void handleASTMethodDecl(ASTMethodDecl node) {
  }

  @Override
  protected void handleASTMethodDef(ASTMethodDef node) {
  }

  @Override
  protected void handleASTNestedExpr(ASTNestedExpr node) {
  }

  @Override
  protected void handleASTNewStat(ASTNewStat node) {
  }

  @Override
  protected void handleASTNotFact(ASTNotFact node) {
  }

  @Override
  protected void handleASTNullFact(ASTNullFact node) {
  }

  @Override
  protected void handleASTOrExpr(ASTOrExpr node) {
  }

  @Override
  protected void handleASTOutputStat(ASTOutputStat node) {
  }

  @Override
  protected void handleASTParamKind(ASTParamKind node) {
  }

  @Override
  protected void handleASTPointer(ASTPointer node) {
  }

  @Override
  protected void handleASTProgram(ASTProgram node) {
  }

  @Override
  protected void handleASTQualifier(ASTQualifier node) {
  }

  @Override
  protected void handleASTReal(ASTReal node) {
  }

  @Override
  protected void handleASTRelExpr(ASTRelExpr node) {
  }

  @Override
  protected void handleASTRepeatStat(ASTRepeatStat node) {
  }

  @Override
  protected void handleASTReturnStat(ASTReturnStat node) {
  }

  @Override
  protected void handleASTReturnType(ASTReturnType node) {
  }

  @Override
  protected void handleASTSelector(ASTSelector node) {
  }

  @Override
  protected void handleASTSimpleExpr(ASTSimpleExpr node) {
  }

  @Override
  protected void handleASTSingleOutput(ASTSingleOutput node) {
  }

  @Override
  protected void handleASTStart(ASTStart node) {
  }

  @Override
  protected void handleASTStat(ASTStat node) {
  }

  @Override
  protected void handleASTString(ASTString node) {
  }

  @Override
  protected void handleASTTerm(ASTTerm node) {
  }

  @Override
  protected void handleASTTextStat(ASTTextStat node) {
  }

  @Override
  protected void handleASTThisFact(ASTThisFact node) {
  }

  @Override
  protected void handleASTTrueFact(ASTTrueFact node) {
  }

  @Override
  protected void handleASTType(ASTType node) {
  }

  @Override
  protected void handleASTTypeDecl(ASTTypeDecl node) {
  }

  @Override
  protected void handleASTTypeSpec(ASTTypeSpec node) {
  }

  @Override
  protected void handleASTVarDecl(ASTVarDecl node) {
  }

  @Override
  protected void handleASTVarSpec(ASTVarSpec node) {
  }

  @Override
  protected void handleASTWhileStat(ASTWhileStat node) {
  }

}
